<?php
/**
 * 用户配方管理
 * 
 * @author  Lee<a605333742@gmail.com>
 * @time    2016-07-31
 */
namespace Admin\Controller;

class RecipeController extends CommonController{
    /*
     * 构造函数
     * 
     * @return #
     */
    public function _initialize() {
        parent::_initialize();
        $this->db       =new \Model\RecipeModel();
        $this->db_info  =new \Model\RecipecolorModel();
    }
    
    /*
     * 用户配方列表
     * 
     * @return #
     */
    public function index(){
        $map=$this->_search("Recipe");
        $map['state']   =2;
        if(session('type')<2){
            $map['userId'] =session("authId");
        }
        $sortBy     ='top';
        $sort       =desc;
        $recipeList =$this->_list($this->db,$map,$sortBy,$sort);
        $this->assign("recipeList",$recipeList);
        $this->assign("act",1);
        show_bug($recipeList);exit;
        $this->display();
    }
    
    /*
     * 待审核用户配方列表
     * 
     * @return #
     */
    public function auditRecipe(){
        $map=$this->_search("Recipe");
        $map['state']   =1;
        if(session('type')<2){
            $map['userId'] =session("authId");
        }
        $sortBy     ='top';
        $sort       =desc;
        $recipeList =$this->_list($this->db,$map,$sortBy,$sort);
        $this->assign("recipeList",$recipeList);
        $this->assign("act",1);
        show_bug($recipeList);exit;
        $this->display("index");
    }
    
    /*
     * 审核批量审核信息
     * 
     * @return bool
     */
    public function alledit(){       
        $map['id']      =I("request.id",'',"int");
        $map['state']   =2;
        if($this->db->edits($map)){            
            $this->success("审核成功",U("index"));
        }else{
            $this->error("审核失败",U("index"));
        }
    }
    
    /*
     * 待审核，批量待审核
     * 
     * @return #
     */
    public function audit(){
        $map['id']      =I("request.id",'',"int");
        $map['state']   =1;
        if($this->db->edits($map)){            
            $this->success("待审核成功",U("index"));
        }else{
            $this->error("待审核失败",U("index"));
        }
    }
    
    /*
     * 删除，批量删除求购信息
     * 
     * @return #
     */
    public function del(){
        $map['id']      =I("request.id",'',"int");
        $map['state']   =3;
        if($this->db->edits($map)){            
            $this->success("删除成功",U("index"));
        }else{
            $this->error("删除失败",U("index"));
        }
    }
    
    /*
     * 配方详情表
     * 
     * @return #
     */
    public function recipeInfo(){
        $map        =$this->_search("Recipecolor");
        $map['id']  =I("request.id",'',"int");
        $infoList   =$this->_list($this->db_info,$map);
        $this->assign("infoList",$infoList);
        $this->display();
    }
    
    /*
     * 删除、批量删除配方
     * 
     * @return #
     */
    public function delInfo(){
        $map['id']      =I("request.id");
        if($this->db->del($map)){            
            $this->success("删除成功",U("index"));
        }else{
            $this->error("删除失败",U("index"));
        }
    }
}